/**
 * 
 */
package com.aodesoft.demo.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.aodesoft.demo.dao.DemoDao;
import com.aodesoft.pojo.Demo;
import com.googlecode.genericdao.search.Search;
@Service
public class DemoService {
	@Resource
	private DemoDao demoDao;
	
	/**
	 * 分页查询
	 * @author tang
	 * @date 2011-12-6
	 * @param pageSize 每页显示数目
	 * @param pageIndex 第几页
	 * @return
	 */
	public List<Demo> getList(int pageSize,int pageIndex ){
		Search s=new Search();
		//按ID降序
		s.addSortDesc("id");
		//每页显示数目
		s.setMaxResults(pageSize);
		//第几页
		s.setPage(pageIndex);
		//执行查询
		List<Demo> lst= demoDao.search(s);
		return lst;
	}
	
	/**
	 * 添加一条记录	
	 * @author tang
	 * @date 2011-12-4
	 * @param demo
	 */
	public void add(Demo demo){
		demoDao.save(demo);
	}
	/**
	 * 查询所有
	 * @author tang
	 * @date 2011-12-4
	 * @return
	 */
	public List<Demo> selectAll(){
		return demoDao.findAll();
	}
	/**
	 * @author tang
	 * @date 2011-12-4
	 */
	public void queryDesc() {
		// TODO Auto-generated method stub
		demoDao.queryDesc();
	}
	public void insertService(Demo demo){
		demoDao.insertTest(demo);
	}
	
	public void querySomeField(){
		Search s=new Search();
		s.setResultMode(Search.RESULT_MAP);
		s.addField("id");
		s.addField("title");
		System.out.println(demoDao.search(s));
	}
	public Boolean delete(int id){
		return demoDao.remove(new Demo(id));
	}
	/**
	 * 获取记录总数
	 * @author tang
	 * @date 2011-12-11
	 * @return
	 */
	public int count(){
		return demoDao.count(null);
	}
}
